# -*- coding:utf-8 -*-


from WebautoTest.base.base_element_enmu import Element as Ele
from WebautoTest.base.base_pack_element import Packelement
import time


class PagesObjects:
    """
    page层
    yaml文件参数配置
    is_move:是否运行用例（true运行，false用例失败）
    """

    def __init__(self, yaml_parameter):
        self.driver = yaml_parameter["driver"]
        self.Packelement = ""
        self.test_case = yaml_parameter["test_case"]
        self.info = self.test_case["info"]
        self.case = self.test_case["case"]
        self.check = self.test_case["check"]
        self.caseName = yaml_parameter["caseName"]
        self.is_move = True
        self.msg = ""

    """
    操作步骤
    """

    def operate(self):
        self.Packelement = Packelement(self.driver)
        for case in self.case:
            self.Packelement.gather_ele(case)
            if case.get("is_time", 0) is not None and case.get("is_time", 0) != 0:
                time.sleep(case["is_time"])
                print(f"==等待{case['is_time']}秒==")
            else:
                pass
            # if case.get("operate_type", "0") == Ele.SWITCH_DEFAULT_FRAME:
            #     self.driver.switch_to.default_content()
            #     print("--切换默认iframe---")
            # if case.get("operate_type", "0") == Ele.SWITCH_PARENT_FRAME:
            #     self.driver.switch_to.parent_frame()
            #     print("--切换默认iframe---")
    '''
    检查点
    '''

    def check(self):
        result = True
        if self.is_move:
            for case_content in self.check:
                if case_content.get("check", Ele.DEFAULT_CHECK) == Ele.DEFAULT_CHECK:
                    print(1)
                    result = False
                    break
                if case_content.get("check", Ele.DEFAULT_CHECK) == Ele.CONTRARY:
                    print(2)
                    result = False
                    break
